/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
 var min;
 var hour;
 var auten;
 var year;
 var mount;
 var day;
 var img = false;
 var img_p ="";
 var img_sh ="";
 var cpx = "hello world";
 function getauthenticity(id){
     alert(id);
     var form = document.getElementById(id);
     var text = form.getInputs('hidden');
     auten = text[1].value;
 }
   /**คะ rubyprojectz@gmail.com
     * [03:22:04] ­พาส 011706952
     *   authenticity_token	5qNN9pY+vfz3PmMBTXe2Gzdxj9GL5nBUx5/WzVCFXdc=
     *   commit	Create
     *   listplan[datetime(1i)]	2010
     *   listplan[datetime(2i)]	3
     *   listplan[datetime(3i)]	9
     *   listplan[datetime(4i)]	04
     *   listplan[datetime(5i)]	14
     *   listplan[plan_id]	rr
     *   listplan[subtourist_id]	ss **/
 function selectmount(){
   mount = 'listplan[datetime(2i)]';
 }

function selectyear(){
     year ='listplan[datetime(1i)]';
 }
function selectday(){
    day = 'listplan[datetime(3i)]';
 }
function selectminute(){
    min = 'listplan[datetime(5i)]';
 }
function selecthours(){
    hour = 'listplan[datetime(4i)]';
 }
function updatelistplan(user,id_subtourist) {
     var url    = '/plans/'+id_plan+'/listplans';
     var form   = $('new_map');
      var text;
     if(form!=null)
        text  = form.getInputs('hidden');
        /*listplan[plan_id]
         *listplan[subtourist_id 1
         *alert(id_plan);
         *alert(text[0].value ); */
        var pars   = 'authenticity_token=' + text[0].value + '&commit=Create';
            pars  += '&listplan[plan_id]='+this.id_plan+'&listplan[subtourist_id]='+id_subtourist;
        var myAjax = new Ajax.Request( url, {method: 'post', parameters: pars, onComplete: alert('complete..')} );
}
function updatetime(id,list,plan){
    var f = $(id);
    var ch = f.value.split(",");
    var yt = ch[1].split(" ");
    var y = yt[1];
   // alert(y);
    var hm = yt[2].split(":");
    var h = hm[0];
   // alert(h);
    var m = hm[1];
   // alert(m);
    var dm = ch[0].split(" ");
    var d  = dm[1];
  //  alert(d);
    var mt = mounts(dm[0]);
 //   alert(mt);
    alert( f.value+' '+ch[0] +' '+ch[1]);
     /*   listplan[datetime(1i)]	2010
     *   listplan[datetime(2i)]	3
     *   listplan[datetime(3i)]	9
     *   listplan[datetime(4i)]	04
     *   listplan[datetime(5i)]	14 */
     var par ='_method=put&authenticity_token=' + auten + '&commit=Update'+
              '&listplan[datetime(1i)]='+y+
              '&listplan[datetime(2i)]='+mt+
              '&listplan[datetime(3i)]='+d+
              '&listplan[datetime(4i)]='+h+
              '&listplan[datetime(5i)]='+m;
     var url    = '/plans/'+plan+'/listplans/'+list;
     var myAjax = new Ajax.Request( url, {method: 'post', parameters: par, onComplete: alert('complete..')} );
}
function mounts(m){
    if(m=='January')
        return 1;
    else if(m=='February')
        return 2;
    else if(m=='March')
        return 3;
    else if(m=='April')
        return 4;
    else if(m=='May')
        return 5;
    else if(m=='June')
        return 6;
    else if(m=='July')
        return 7;
    else if(m=='August')
        return 8;
    else if(m=='September')
        return 9;
    else if(m=='October')
        return 10;
    else if(m=='November')
        return 11;
    else if(m=='December')
        return 12;
}
function displaySelectedDateTime(dom_id) {
  $(document).ready(function() {
    setInterval(function(){
      $.get('/app/Datetime/selection', {field_key: dom_id}, function(data){
        $('#'+dom_id).val(data);
      });
      return false;
    }, 300);
  });
}
function popupDateTimePicker(flag, title, field_key) {
  $.get('/app/Datetime/popup', {flag: flag, title: title, field_key: field_key});
  return false;
}
function changeLocation(date) {
		year = date.getFullYear();
		month = date.getMonth() + 1;
		day = date.getDate();
		if (month < 10) {
			month = "0" + month;
		}
		if (day < 10) {
			day = "0" + day;
		}
		location.href = 'http://google.com/search?q=' + year + '-' + month + '-' + day;
	}
function updatedesc(id,list,plan){
    var f = $(id).value;
 //   alert(mt);
    //alert(f);
     /*   listplan[datetime(1i)]	2010
     *   listplan[datetime(2i)]	3
     *   listplan[datetime(3i)]	9
     *   listplan[datetime(4i)]	04
     *   listplan[datetime(5i)]	14 */
     var par ='_method=put&authenticity_token=' + auten + '&commit=Update'+
              '&listplan[desc]='+f;
     var url    = '/plans/'+plan+'/listplans/'+list;
     var myAjax = new Ajax.Request( url, {method: 'post', parameters: par, onComplete: alert('complete..')} );
}
